package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.FeeKey;
import com.atguigu.lease.model.entity.FeeValue;
import com.atguigu.lease.web.admin.mapper.FeeKeyMapper;
import com.atguigu.lease.web.admin.mapper.FeeValueMapper;
import com.atguigu.lease.web.admin.service.FeeKeyService;
import com.atguigu.lease.web.admin.vo.fee.FeeKeyVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【fee_key(杂项费用名称表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey>
        implements FeeKeyService {

    @Autowired
    private FeeKeyMapper feeKeyMapper;

    @Autowired
    private FeeValueMapper feeValueMapper;

    @Override
    public void deleteFeeKeyById(Long feeKeyId) {
        //删除杂费名称
        feeKeyMapper.deleteById(feeKeyId);
        //删除杂费名称下面的杂费值
        //当fee_value表中的fee_key_id与fee_key表中的id相同时，删除fee_value表中的记录
        LambdaQueryWrapper<FeeValue> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FeeValue::getFeeKeyId, feeKeyId);
        feeValueMapper.delete(queryWrapper);

    }

    @Override
    public List<FeeKeyVo> feeInfoList() {
        List<FeeKeyVo> list = feeKeyMapper.feeInfoList();
        return list;
    }
}




